import requests


class TestIHRMlogin:
    # 登录成功
    def test01_login(self):
        print("-----------------------登录成功--------------------------------")
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        body = {"mobile": "13800000002", "password": "123456"}
        resp = requests.post(url=url, headers=header, json=body)
        print("resp=", resp.json())
        assert 200 == resp.status_code
        assert True == resp.json().get("success")
        assert 10000 == resp.json().get("code")
        assert "操作成功！" == resp.json().get("message")
    # 登录失败
    def test02_login(self):
        print("------------------------登录失败,用户名错误---------------------------------")
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        body = {"mobile": "1380000000222", "password": "123456"}
        resp = requests.post(url=url, headers=header, json=body)
        print("resp=", resp.json())
        assert 200 == resp.status_code
        assert False == resp.json()["success"]
        assert 20001 == resp.json()["code"]
        assert "用户名或密码错误" == resp.json()["message"]
    # 登录失败
    def test03_login(self):
        print("------------------------登录失败,密码错误---------------------------------")
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        body = {"mobile": "13800000002", "password": "123888"}
        resp = requests.post(url=url, headers=header, json=body)
        print("resp=", resp.json())
        assert 200 == resp.status_code
        assert False == resp.json()["success"]
        assert 20001 == resp.json()["code"]
        assert "用户名或密码错误" == resp.json()["message"]

